<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Counted Stream 💡</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Beast">
<link rel="up" href="../layered_streams.html" title="Layered Streams">
<link rel="prev" href="../layered_streams.html" title="Layered Streams">
<link rel="next" href="../buffer_types.html" title="Buffer Types">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../layered_streams.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../layered_streams.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../buffer_types.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="beast.using_io.layered_streams.counted_stream_example"></a><a class="link" href="counted_stream_example.html" title="Counted Stream 💡">Counted
        Stream 💡</a>
</h4></div></div></div>
<p>
          This example shows the definition of a layered stream which keeps individual
          counts of the total number of bytes read from and written to the next layer.
          It meets the requirements for synchronous and asynchronous read and write
          streams:
        </p>
<pre class="programlisting"><span class="comment">// A layered stream which counts the bytes read and bytes written on the next layer</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">NextLayer</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">counted_stream</span>
<span class="special">{</span>
    <span class="identifier">NextLayer</span> <span class="identifier">next_layer_</span><span class="special">;</span>              <span class="comment">// Reads and writes are passed through to this</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bytes_read_</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>        <span class="comment">// Holds the total bytes read</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bytes_written_</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>     <span class="comment">// Holds the total bytes written</span>

    <span class="comment">// This is the "initiation" object passed to async_initiate to start the operation</span>
    <span class="keyword">struct</span> <span class="identifier">run_read_op</span>
    <span class="special">{</span>
        <span class="keyword">template</span><span class="special">&lt;</span>
            <span class="keyword">class</span> <span class="identifier">ReadHandler</span><span class="special">,</span>
            <span class="keyword">class</span> <span class="identifier">MutableBufferSequence</span><span class="special">&gt;</span>
        <span class="keyword">void</span>
        <span class="keyword">operator</span><span class="special">()(</span>
            <span class="identifier">ReadHandler</span><span class="special">&amp;&amp;</span> <span class="identifier">handler</span><span class="special">,</span>
            <span class="identifier">counted_stream</span><span class="special">*</span> <span class="identifier">stream</span><span class="special">,</span>
            <span class="identifier">MutableBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">)</span>
        <span class="special">{</span>
            <span class="keyword">using</span> <span class="identifier">handler_type</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">decay</span><span class="special">&lt;</span><span class="identifier">ReadHandler</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">;</span>

            <span class="comment">// async_base handles all of the composed operation boilerplate for us</span>
            <span class="keyword">using</span> <span class="identifier">base</span> <span class="special">=</span> <span class="identifier">async_base</span><span class="special">&lt;</span>
                <span class="identifier">handler_type</span><span class="special">,</span> <span class="identifier">beast</span><span class="special">::</span><span class="identifier">executor_type</span><span class="special">&lt;</span><span class="identifier">NextLayer</span><span class="special">&gt;&gt;;</span>

            <span class="comment">// Our composed operation is implemented as a completion handler object</span>
            <span class="keyword">struct</span> <span class="identifier">op</span> <span class="special">:</span> <span class="identifier">base</span>
            <span class="special">{</span>
                <span class="identifier">counted_stream</span><span class="special">&amp;</span> <span class="identifier">stream_</span><span class="special">;</span>

                <span class="identifier">op</span><span class="special">(</span> <span class="identifier">counted_stream</span><span class="special">&amp;</span> <span class="identifier">stream</span><span class="special">,</span>
                    <span class="identifier">handler_type</span><span class="special">&amp;&amp;</span> <span class="identifier">handler</span><span class="special">,</span>
                    <span class="identifier">MutableBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">)</span>
                    <span class="special">:</span> <span class="identifier">base</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">handler</span><span class="special">),</span> <span class="identifier">stream</span><span class="special">.</span><span class="identifier">get_executor</span><span class="special">())</span>
                    <span class="special">,</span> <span class="identifier">stream_</span><span class="special">(</span><span class="identifier">stream</span><span class="special">)</span>
                <span class="special">{</span>
                    <span class="comment">// Start the asynchronous operation</span>
                    <span class="identifier">stream_</span><span class="special">.</span><span class="identifier">next_layer</span><span class="special">().</span><span class="identifier">async_read_some</span><span class="special">(</span><span class="identifier">buffers</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="keyword">this</span><span class="special">));</span>
                <span class="special">}</span>

                <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">error_code</span> <span class="identifier">ec</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bytes_transferred</span><span class="special">)</span>
                <span class="special">{</span>
                    <span class="comment">// Count the bytes transferred towards the total</span>
                    <span class="identifier">stream_</span><span class="special">.</span><span class="identifier">bytes_read_</span> <span class="special">+=</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>

                    <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">complete_now</span><span class="special">(</span><span class="identifier">ec</span><span class="special">,</span> <span class="identifier">bytes_transferred</span><span class="special">);</span>
                <span class="special">}</span>
            <span class="special">};</span>

            <span class="identifier">op</span><span class="special">(*</span><span class="identifier">stream</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special">&lt;</span><span class="identifier">ReadHandler</span><span class="special">&gt;(</span><span class="identifier">handler</span><span class="special">),</span> <span class="identifier">buffers</span><span class="special">);</span>
        <span class="special">}</span>
    <span class="special">};</span>

    <span class="comment">// This is the "initiation" object passed to async_initiate to start the operation</span>
    <span class="keyword">struct</span> <span class="identifier">run_write_op</span>
    <span class="special">{</span>
        <span class="keyword">template</span><span class="special">&lt;</span>
            <span class="keyword">class</span> <span class="identifier">WriteHandler</span><span class="special">,</span>
            <span class="keyword">class</span> <span class="identifier">ConstBufferSequence</span><span class="special">&gt;</span>
        <span class="keyword">void</span>
        <span class="keyword">operator</span><span class="special">()(</span>
            <span class="identifier">WriteHandler</span><span class="special">&amp;&amp;</span> <span class="identifier">handler</span><span class="special">,</span>
            <span class="identifier">counted_stream</span><span class="special">*</span> <span class="identifier">stream</span><span class="special">,</span>
            <span class="identifier">ConstBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">)</span>
        <span class="special">{</span>
            <span class="keyword">using</span> <span class="identifier">handler_type</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">decay</span><span class="special">&lt;</span><span class="identifier">WriteHandler</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">;</span>

            <span class="comment">// async_base handles all of the composed operation boilerplate for us</span>
            <span class="keyword">using</span> <span class="identifier">base</span> <span class="special">=</span> <span class="identifier">async_base</span><span class="special">&lt;</span>
                <span class="identifier">handler_type</span><span class="special">,</span> <span class="identifier">beast</span><span class="special">::</span><span class="identifier">executor_type</span><span class="special">&lt;</span><span class="identifier">NextLayer</span><span class="special">&gt;&gt;;</span>

            <span class="comment">// Our composed operation is implemented as a completion handler object</span>
            <span class="keyword">struct</span> <span class="identifier">op</span> <span class="special">:</span> <span class="identifier">base</span>
            <span class="special">{</span>
                <span class="identifier">counted_stream</span><span class="special">&amp;</span> <span class="identifier">stream_</span><span class="special">;</span>

                <span class="identifier">op</span><span class="special">(</span> <span class="identifier">counted_stream</span><span class="special">&amp;</span> <span class="identifier">stream</span><span class="special">,</span>
                    <span class="identifier">handler_type</span><span class="special">&amp;&amp;</span> <span class="identifier">handler</span><span class="special">,</span>
                    <span class="identifier">ConstBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">)</span>
                    <span class="special">:</span> <span class="identifier">base</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">handler</span><span class="special">),</span> <span class="identifier">stream</span><span class="special">.</span><span class="identifier">get_executor</span><span class="special">())</span>
                    <span class="special">,</span> <span class="identifier">stream_</span><span class="special">(</span><span class="identifier">stream</span><span class="special">)</span>
                <span class="special">{</span>
                    <span class="comment">// Start the asynchronous operation</span>
                    <span class="identifier">stream_</span><span class="special">.</span><span class="identifier">next_layer</span><span class="special">().</span><span class="identifier">async_write_some</span><span class="special">(</span><span class="identifier">buffers</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="keyword">this</span><span class="special">));</span>
                <span class="special">}</span>

                <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">error_code</span> <span class="identifier">ec</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bytes_transferred</span><span class="special">)</span>
                <span class="special">{</span>
                    <span class="comment">// Count the bytes transferred towards the total</span>
                    <span class="identifier">stream_</span><span class="special">.</span><span class="identifier">bytes_written_</span> <span class="special">+=</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>

                    <span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">complete_now</span><span class="special">(</span><span class="identifier">ec</span><span class="special">,</span> <span class="identifier">bytes_transferred</span><span class="special">);</span>
                <span class="special">}</span>
            <span class="special">};</span>

            <span class="identifier">op</span><span class="special">(*</span><span class="identifier">stream</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special">&lt;</span><span class="identifier">WriteHandler</span><span class="special">&gt;(</span><span class="identifier">handler</span><span class="special">),</span> <span class="identifier">buffers</span><span class="special">);</span>
        <span class="special">}</span>
    <span class="special">};</span>

<span class="keyword">public</span><span class="special">:</span>
    <span class="comment">/// The type of executor used by this stream</span>
    <span class="keyword">using</span> <span class="identifier">executor_type</span> <span class="special">=</span> <span class="identifier">beast</span><span class="special">::</span><span class="identifier">executor_type</span><span class="special">&lt;</span><span class="identifier">NextLayer</span><span class="special">&gt;;</span>

    <span class="comment">/// Constructor</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">&gt;</span>
    <span class="keyword">explicit</span>
    <span class="identifier">counted_stream</span><span class="special">(</span><span class="identifier">Args</span><span class="special">&amp;&amp;...</span> <span class="identifier">args</span><span class="special">)</span>
        <span class="special">:</span> <span class="identifier">next_layer_</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special">&lt;</span><span class="identifier">Args</span><span class="special">&gt;(</span><span class="identifier">args</span><span class="special">)...)</span>
    <span class="special">{</span>
    <span class="special">}</span>

    <span class="comment">/// Returns an instance of the executor used to submit completion handlers</span>
    <span class="identifier">executor_type</span> <span class="identifier">get_executor</span><span class="special">()</span> <span class="keyword">noexcept</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">next_layer_</span><span class="special">.</span><span class="identifier">get_executor</span><span class="special">();</span>
    <span class="special">}</span>

    <span class="comment">/// Returns a reference to the next layer</span>
    <span class="identifier">NextLayer</span><span class="special">&amp;</span> <span class="identifier">next_layer</span><span class="special">()</span> <span class="keyword">noexcept</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">next_layer_</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Returns a reference to the next layer</span>
    <span class="identifier">NextLayer</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">next_layer</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">next_layer_</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Returns the total number of bytes read since the stream was constructed</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bytes_read</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">bytes_read_</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Returns the total number of bytes written since the stream was constructed</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bytes_written</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">bytes_written_</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Read some data from the stream</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">MutableBufferSequence</span><span class="special">&gt;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">read_some</span><span class="special">(</span><span class="identifier">MutableBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">auto</span> <span class="keyword">const</span> <span class="identifier">bytes_transferred</span> <span class="special">=</span> <span class="identifier">next_layer_</span><span class="special">.</span><span class="identifier">read_some</span><span class="special">(</span><span class="identifier">buffers</span><span class="special">);</span>
        <span class="identifier">bytes_read_</span> <span class="special">+=</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
        <span class="keyword">return</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Read some data from the stream</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">MutableBufferSequence</span><span class="special">&gt;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">read_some</span><span class="special">(</span><span class="identifier">MutableBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">,</span> <span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">auto</span> <span class="keyword">const</span> <span class="identifier">bytes_transferred</span> <span class="special">=</span> <span class="identifier">next_layer_</span><span class="special">.</span><span class="identifier">read_some</span><span class="special">(</span><span class="identifier">buffers</span><span class="special">,</span> <span class="identifier">ec</span><span class="special">);</span>
        <span class="identifier">bytes_read_</span> <span class="special">+=</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
        <span class="keyword">return</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Write some data to the stream</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">ConstBufferSequence</span><span class="special">&gt;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">write_some</span><span class="special">(</span><span class="identifier">ConstBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">auto</span> <span class="keyword">const</span> <span class="identifier">bytes_transferred</span> <span class="special">=</span> <span class="identifier">next_layer_</span><span class="special">.</span><span class="identifier">write_some</span><span class="special">(</span><span class="identifier">buffers</span><span class="special">);</span>
        <span class="identifier">bytes_written_</span> <span class="special">+=</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
        <span class="keyword">return</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Write some data to the stream</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">ConstBufferSequence</span><span class="special">&gt;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">write_some</span><span class="special">(</span><span class="identifier">ConstBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">,</span> <span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">auto</span> <span class="keyword">const</span> <span class="identifier">bytes_transferred</span> <span class="special">=</span> <span class="identifier">next_layer_</span><span class="special">.</span><span class="identifier">write_some</span><span class="special">(</span><span class="identifier">buffers</span><span class="special">,</span> <span class="identifier">ec</span><span class="special">);</span>
        <span class="identifier">bytes_written_</span> <span class="special">+=</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
        <span class="keyword">return</span> <span class="identifier">bytes_transferred</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="comment">/// Read some data from the stream asynchronously</span>
    <span class="keyword">template</span><span class="special">&lt;</span>
        <span class="keyword">class</span> <span class="identifier">MutableBufferSequence</span><span class="special">,</span>
        <span class="keyword">class</span> <span class="identifier">ReadHandler</span> <span class="special">=</span>
            <span class="identifier">net</span><span class="special">::</span><span class="identifier">default_completion_token_t</span><span class="special">&lt;</span><span class="identifier">executor_type</span><span class="special">&gt;&gt;</span>
    <span class="identifier">BOOST_BEAST_ASYNC_RESULT2</span><span class="special">(</span><span class="identifier">ReadHandler</span><span class="special">)</span>
    <span class="identifier">async_read_some</span><span class="special">(</span>
        <span class="identifier">MutableBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">,</span>
        <span class="identifier">ReadHandler</span><span class="special">&amp;&amp;</span> <span class="identifier">handler</span> <span class="special">=</span>
            <span class="identifier">net</span><span class="special">::</span><span class="identifier">default_completion_token_t</span><span class="special">&lt;</span><span class="identifier">executor_type</span><span class="special">&gt;{})</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">net</span><span class="special">::</span><span class="identifier">async_initiate</span><span class="special">&lt;</span>
            <span class="identifier">ReadHandler</span><span class="special">,</span>
            <span class="keyword">void</span><span class="special">(</span><span class="identifier">error_code</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">)&gt;(</span>
                <span class="identifier">run_read_op</span><span class="special">{},</span>
                <span class="identifier">handler</span><span class="special">,</span>
                <span class="keyword">this</span><span class="special">,</span>
                <span class="identifier">buffers</span><span class="special">);</span>
    <span class="special">}</span>

    <span class="comment">/// Write some data to the stream asynchronously</span>
    <span class="keyword">template</span><span class="special">&lt;</span>
        <span class="keyword">class</span> <span class="identifier">ConstBufferSequence</span><span class="special">,</span>
        <span class="keyword">class</span> <span class="identifier">WriteHandler</span> <span class="special">=</span>
            <span class="identifier">net</span><span class="special">::</span><span class="identifier">default_completion_token_t</span><span class="special">&lt;</span><span class="identifier">executor_type</span><span class="special">&gt;&gt;</span>
    <span class="identifier">BOOST_BEAST_ASYNC_RESULT2</span><span class="special">(</span><span class="identifier">WriteHandler</span><span class="special">)</span>
    <span class="identifier">async_write_some</span><span class="special">(</span>
        <span class="identifier">ConstBufferSequence</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">buffers</span><span class="special">,</span>
        <span class="identifier">WriteHandler</span><span class="special">&amp;&amp;</span> <span class="identifier">handler</span> <span class="special">=</span>
            <span class="identifier">net</span><span class="special">::</span><span class="identifier">default_completion_token_t</span><span class="special">&lt;</span>
                <span class="identifier">executor_type</span><span class="special">&gt;{})</span>
    <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">net</span><span class="special">::</span><span class="identifier">async_initiate</span><span class="special">&lt;</span>
            <span class="identifier">WriteHandler</span><span class="special">,</span>
            <span class="keyword">void</span><span class="special">(</span><span class="identifier">error_code</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">)&gt;(</span>
                <span class="identifier">run_write_op</span><span class="special">{},</span>
                <span class="identifier">handler</span><span class="special">,</span>
                <span class="keyword">this</span><span class="special">,</span>
                <span class="identifier">buffers</span><span class="special">);</span>
    <span class="special">}</span>
<span class="special">};</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie
      Falco<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../layered_streams.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../layered_streams.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../buffer_types.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
